#include "driver.h"

NTSTATUS
DDControlRoutine(IN PDEVICE_OBJECT fdo, IN PIRP Irp) {

	NTSTATUS status;
	PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp);
	//PIO_STACK_LOCATION next = IoGetNextIrpStackLocation(Irp);

	//IoCopyCurrentIrpStackLocationToNext(Irp);

	if (stack->FileObject != NULL) {

		PCHAR buf;
		// there should be filter
		
		DbgMess(("(MajorFunction = 0x%X) Access to file %ws for processid 0x%x", stack->MajorFunction, stack->FileObject->FileName.Buffer, PsGetCurrentProcessId()));

		buf = ExAllocatePool( NonPagedPool, MAXPATHLEN*sizeof(WCHAR) );

		if (buf) {
			DDGetFullPath(FALSE, stack->FileObject, (PDD_DEVICE)fdo->DeviceExtension, buf); 
			DbgMess(("file is %s", buf));
			ExFreePool(buf);
		}

		
	}

	DbgMess(("Pass query to next device"));

	IoSkipCurrentIrpStackLocation(Irp);
	status = IoCallDriver(((PDD_DEVICE)fdo->DeviceExtension)->FileSystem, Irp);

	DbgMess(("Status is 0x%X", status));

	DbgMess(("Information = %ld", Irp->IoStatus.Information));

	return status;
}